package service;

import dao.UserDao;
import entity.User;

import javax.servlet.ServletException;
import java.io.IOException;
import java.util.Map;

public class UserService {

    private UserDao userDao = new UserDao();

    public User findByUsername(String username) {
        return userDao.findByUsername(username);
    }

    public User findByEmail(String email) {
        return userDao.findByEmail(email);
    }

    /**
     * 注册用户
     * @param param
     */
    public void register(Map<String, String> param) {
        userDao.register(param);
    }

    /**
     * 登录，去数据库中比对信息
     * @param param
     */
    public User login(Map<String, String> param) {
        return userDao.login(param);
    }

    public User findById(Long userId) {
        return userDao.findById(userId);
    }

    /**
     * 根据扫码登入的id查询user
     * @param wxOpenId
     * @return
     */
    public User findByWxOpenId(String wxOpenId) {
        return userDao.findByWxOpenId(wxOpenId);

    }

    /**
     * 第一次微信登录，注册user
     * @param user
     */
    public void WxRegister(User user) {
        userDao.WxRegister(user);
    }
}
